********************************************************************************
****************            Table 1 and Table 2                   **************
********************************************************************************
use "voting exchange rate data 15 July 2023.dta", clear
xtset ifscode year

**Variable Labeling**
label var cap100 "Capital"
label var cur100 "Current"
label var underval "Exchange Rate Undervaluation"
label var wbcode "World Bank Country Code"
label var underval91 "Exchange Rate Unvervaluation_91"
label var lgrow9 "Log Growth"
label var balance9 "Trade/GDP Trade Balance"
label var popgr9 "Population Growth (mean)"
label var trade_gdp "Trade/GDP"
label var inflation "Inflation (mean)" 
label var unemployment_ilo_est "Unemployment ILO Estimate (mean)"
label var unemployment_nat_est "Unemployment National Estimate (mean)"
label var cap100 "Capital Account"
label var fh_civ "Civil Liberties Rating (Freedom House)"
label var fh_pol "Political Rights Rating"
label var lvau "De Jure and De Facto Central Bank Independence Index unweighted"
label var lvaw "De Jure and De Facto Central Bank Independence Index weighted"
label var oil_rents "Oil Rents"
label var polcomp "Political Competition (mean)"
label var resource_rents "Resource Rents"
label var pr "Proportional Representation"
label var EU "European Union membership"
label var year "Year"
label var banking_center "Banking Center"
label var monetary_union "Monetary Union"
label var lgrow9 "Log Growth"
label var lnrealgdp9 "Log Income PC"
label var polity2 "Polity 2"
label var balance9 "Trade Balance/GDP"
label var exchangerateregime_fine "Exchange Rate Regime Rheinart and Rogoff (Fine classification)"
label var peg "Standard Shambaugh 2004 classification (1= peg,0= nonpeg) (Shambaugh)"
label var ifscode "International Financial Statistics Database Country Code"
label var ifs "International Financial Statistics Database Country"
label var polcomp "Political Competition Concept"
label var ltrade9 "Log Trade Openess (mean)"
label var cowcode "Country Codes according to the Correlates of War Project"
label var oecd "OECD membership"
label var GEO "Continent"
label var polity4 "Polity 4"
label var exchangerateregime_coarse "Exchange Rate Regime (Coarse Classification)"
label var unemploymerge "Unemployment Merge"
label var linvest9 "Log Investment"
label var linflation "Lag Inflation"
label var l2underval "Lag 2 Undervaluation"
label var l2underval91 "Lag 2 Undervaluation91"
label var Inct2019 "Incumbent Vote Share"
label var Inct12019 "Incumbent Vote Share 1"
label var Inct22019 "Incumbent Vote Share 2"
label var l2undervalreg91 "Lag_2 Exchange Rate Undervaluation"


ssc install interflex, replace all
ssc install reghdfe
ssc install ftools

xtset ifscode year, delta(1)


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

**# Bookmark #2

////////////////////////////////////////////////////////////////////////////////
****************                     Table 1                      **************
////////////////////////////////////////////////////////////////////////////////

eststo clear

**********                       1. Simple collider   			      **********
eststo: xtreg dInct2019  l.d.underval91  if banking_center!=1 & polity>6, vce(cluster ifscode)

**********                       2. Additive collider  			      **********
eststo: xtreg dInct2019  l.d.underval91  l2.underval91  if banking_center!=1 & polity>6 , vce(cluster ifscode)


**********                    3. Multiplicative collider  			  **********
eststo: xtreg dInct2019  c.l.d.underval91##c.l2.underval91 if banking_center!=1 & polity>6, vce(cluster ifscode)

margins, dydx(l.d.underval91 ) at(l2.underval91 =(-1.2(.1) .7)  )
marginsplot, title("Estimated Effect of Currency Depreciation t-1 on Incumbent Vote Share") ytitle("Avg Marginal Effect of ΔεXRi,t-1 on Vote Shares") xtitle("Currency Valuation at t-2 (negative values equal overvaluation)") yline(0) recastci(rline) recast(line)  legend(off) addplot( hist l2underval91 if e(sample) , width(.05) percent mfcolor(none) fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)))

interflex dInct2019  ldunderval91  l2underval91  if  banking_center!=1 & polity>6  , cl(ifscode) title("Interflex model from T1.3")
//p value of Wald test: 0.0018

***********                    4. Unit/Year FE - Base               ************
eststo: xtreg dInct2019 i.year l.d.underval91 l.peg_no_euro  l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge l.euro maj_01  if banking_center!=1 & polity>6, fe vce(cluster ifscode)


***********     5. Unit/Year FE - Allow for changes and levels      ************
eststo: xtreg dInct2019 i.year    l.d.underval91  l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge l.euro maj_01  if banking_center!=1 & polity>6 , fe vce(cluster ifscode)


*******     6. Unit/Year FE - Allow for changes to interact with levels ********
eststo: xtreg dInct2019 i.year    c.l.d.underval91##c.l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge  l.euro maj_01 if banking_center!=1 & polity>6, fe vce(cluster ifscode)

margins, dydx(l.d.underval91 ) at(l2.underval91 =(-1.2(.1) .7)  )
marginsplot, title("Estimated Effect of Currency Depreciation t-1 on Incumbent Vote Share") ytitle("Avg Marginal Effect of ΔεXRi,t-1 on Vote Shares") xtitle("RER Valuation εXRi,t-2 (negative values equal overvaluation)") yline(0) recastci(rline) recast(line)  legend(off) addplot( hist l2underval91 if e(sample) , width(.05) percent mfcolor(none) fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)))

interflex dInct2019  ldunderval91  l2underval91 llgrow9 lbalance9 ltrade_gdp lunemploymerge linflation lpeg_no_euro   leuro maj_01 if  banking_center!=1 & polity>6  , fe(ifscode year) cl(ifscode)
//p value of Wald test: 0.5726

*********  				 	 7. Y_{s-1}/Y_{s-2} - Base                 *********       
eststo: xtreg dInct2019 i.year Inct12019 Inct22019 l.d.underval91 l.peg_no_euro  l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge l.euro maj_01  if banking_center!=1 & polity>6 , vce(cluster ifscode)


******  		 8. Y_{s-1}/Y_{s-2} - Allow for changes and levels        ******       
eststo: xtreg dInct2019 i.year Inct12019 Inct22019   l.d.underval91  l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge l.euro maj_01  if banking_center!=1 & polity>6  , vce(cluster ifscode)


******  9. Y_{s-1}/Y_{s-2} - Allow for changes to interact with levels    ******       
eststo: xtreg dInct2019 i.year Inct12019 Inct22019   c.l.d.underval91##c.l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge  l.euro maj_01 if banking_center!=1 & polity>6 , vce(cluster ifscode)
interflex dInct2019  ldunderval91  l2underval91 Inct12019 Inct22019 llgrow9 lbalance9 ltrade_gdp lunemploymerge linflation lpeg_no_euro   leuro maj_01 if  banking_center!=1 & polity>6  , fe( year) cl(ifscode)
//p value of Wald test: 0.4809

esttab * using Table_1.csv,  label b(3) se(3) scalar(r2_w r2_b r2_o N_clust) sfmt( a3 a0) star(* 0.1 ** 0.05 *** 0.01) replace parentheses
eststo clear 


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

**# Bookmark #3

eststo clear
////////////////////////////////////////////////////////////////////////////////
****************                     Table 2                      **************
////////////////////////////////////////////////////////////////////////////////

eststo clear

****************                      OECD                        **************

**********                    1. Multiplicative collider  			  **********
eststo: xtreg dInct2019  c.l.d.underval91##c.l2.underval91 if banking_center!=1 & polity>6 & oecd==1, vce(cluster ifscode)

margins, dydx(l.d.underval91 ) at(l2.underval91 =(-1.2(.1) .7)  )
marginsplot, title("Estimated Effect of Currency Depreciation t-1 on Incumbent Vote Share") ytitle("Avg Marginal Effect of ΔεXRi,t-1 on Vote Shares") xtitle("Currency Valuation at t-2 (negative values equal overvaluation)") yline(0) recastci(rline) recast(line)  legend(off) addplot( hist l2underval91 if e(sample) , width(.05) percent mfcolor(none) fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)))
***compute p-value for Wald test to reject the NULL hypothesis that the linear interaction model and the three-bin model are statisticallyequivalent

interflex dInct2019  ldunderval91  l2underval91  if  banking_center!=1 & polity>6 & oecd==1 , cl(ifscode)
//p value of Wald test: 0.0002


*******     2. Unit/Year FE - Allow for changes to interact with levels ********
eststo: xtreg dInct2019 i.year    c.l.d.underval91##c.l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge l.euro maj_01 if banking_center!=1 & polity>6 & oecd==1, fe vce(cluster ifscode)

margins, dydx(l.d.underval91 ) at(l2.underval91 =(-1.2(.1) .7)  )
marginsplot, title("Estimated Effect of Currency Depreciation t-1 on Incumbent Vote Share") ytitle("Avg Marginal Effect of ΔεXRi,t-1 on Vote Shares") xtitle("Currency Valuation at t-2 (negative values equal overvaluation)") yline(0) recastci(rline) recast(line)  legend(off) addplot( hist l2underval91 if e(sample) , width(.05) percent mfcolor(none) fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)))

interflex dInct2019  ldunderval91  l2underval91 llgrow9 lbalance9 ltrade_gdp lunemploymerge linflation lpeg_no_euro   leuro maj_01 if  banking_center!=1 & polity>6 & oecd==1 , fe(ifscode year) cl(ifscode)
//p value of Wald test: 0.5035



******  3. Y_{s-1}/Y_{s-2} - Allow for changes to interact with levels    ******       
eststo: xtreg dInct2019 i.year Inct12019 Inct22019   c.l.d.underval91##c.l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge  l.euro maj_01 if banking_center!=1 & polity>6 & oecd==1, vce(cluster ifscode)

interflex dInct2019  ldunderval91  l2underval91 Inct12019 Inct22019 llgrow9 lbalance9 ltrade_gdp lunemploymerge linflation lpeg_no_euro   leuro maj_01 if  banking_center!=1 & polity>6 & oecd==1 , fe( year) cl(ifscode)
//p value of Wald test: 0.4321




****************                      non-OECD                        **********

**********                    4. Multiplicative collider  			  **********
eststo: xtreg dInct2019  c.l.d.underval91##c.l2.underval91 if banking_center!=1 & polity>6 & oecd==0, vce(cluster ifscode)
interflex dInct2019  ldunderval91  l2underval91  if  banking_center!=1 & polity>6 & oecd==0 , cl(ifscode)
//p value of Wald test: 0.1826


*******     5. Unit/Year FE - Allow for changes to interact with levels ********
eststo: xtreg dInct2019 i.year    c.l.d.underval91##c.l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge  l.euro maj_01 if banking_center!=1 & polity>6 & oecd==0, fe vce(cluster ifscode)

margins, dydx(l.d.underval91 ) at(l2.underval91 =(-1.2(.1) .7)  )
marginsplot, title("Estimated Effect of Currency Depreciation t-1 on Incumbent Vote Share") ytitle("Avg Marginal Effect of ΔεXRi,t-1 on Vote Shares") xtitle("RER Valuation εXRi,t-2 (negative values equal overvaluation)") yline(0) recastci(rline) recast(line)  legend(off) addplot( hist l2underval91 if e(sample) , width(.05) percent mfcolor(none) fcolor(none) lcolor(gs10) yaxis(2) yscale(alt axis(2)))

interflex dInct2019  ldunderval91  l2underval91 llgrow9 lbalance9 ltrade_gdp lunemploymerge linflation lpeg_no_euro   leuro maj_01 if  banking_center!=1 & polity>6 & oecd==0 , fe(ifscode year) cl(ifscode)
//p value of Wald test: 0.0950


******  6. Y_{s-1}/Y_{s-2} - Allow for changes to interact with levels    ******       
*no change after adding exchange rates
eststo: xtreg dInct2019 i.year Inct12019 Inct22019   c.l.d.underval91##c.l2.underval91 l.peg_no_euro l.lgrow9 l.balance9 l.trade_gdp l.inflation l.unemploymerge  l.euro maj_01 if banking_center!=1 & polity>6 & oecd==0, vce(cluster ifscode)

interflex dInct2019  ldunderval91  l2underval91 Inct12019 Inct22019 llgrow9 lbalance9 ltrade_gdp lunemploymerge linflation lpeg_no_euro   leuro maj_01 if  banking_center!=1 & polity>6 & oecd==0 , fe( year) cl(ifscode)
//p value of Wald test: 0.4733


esttab * using Table_2.csv,  label b(3) se(3) scalar(r2_w r2_b r2_o N_clust) sfmt( a3 a0) star(* 0.1 ** 0.05 *** 0.01) replace parentheses
eststo clear 




